﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace _MetalSlug.Form.OptionScreen
{
    public class DifficultySettingDisplayer : SettingDisplayer
    {
        List<String> DifficultyLevels;
        
        public DifficultySettingDisplayer()
        {
            InitialAttribute("Difficulty:",new Vector2(20, 300),50);
            DifficultyLevels = new List<string>();
            DifficultyLevels.Add("Easy");
            DifficultyLevels.Add("Normal");
            DifficultyLevels.Add("Hard");  
        }

        public override void Draw(SpriteBatch spriteBatch, SpriteFont currentFont, Color defaultColor, Color chosenColor)
        {
            base.Draw(spriteBatch, currentFont, defaultColor, chosenColor);
            float nextPosition = currentFont.MeasureString(Title).X;
            for (int i = 0; i < DifficultyLevels.Count;i++)
            {
                Vector2 sizeOfPrevText = Vector2.Zero;
                if(i>0)
                {
                    sizeOfPrevText = currentFont.MeasureString(DifficultyLevels[i-1]);
                }

                nextPosition += Spacing  + sizeOfPrevText.X;
                Vector2 newPosition = new Vector2(nextPosition + StartPoint.X,StartPoint.Y);
                if (GameUtil.CurrentDifficultyLevel == i)
                {
                    spriteBatch.DrawString(currentFont, DifficultyLevels[i], newPosition, chosenColor);
                }
                else
                {
                    spriteBatch.DrawString(currentFont, DifficultyLevels[i], newPosition, defaultColor);
                }
            }
            
        }

        public override void ChangeOption()
        {
            if (UserInput.isKeyClicked(Keys.Left))
            {
                if (GameUtil.CurrentDifficultyLevel > 0)
                {
                    GameUtil.CurrentDifficultyLevel--;
                }
            }

            if (UserInput.isKeyClicked(Keys.Right))
            {
                if (GameUtil.CurrentDifficultyLevel < DifficultyLevels.Count - 1)
                {
                    GameUtil.CurrentDifficultyLevel++;
                }
            }
        }
    }
}
